<script setup>
// 消耗提示组件
import baseModel from "@/components/baseModel/baseModel.vue";
import { computed, reactive, ref } from "vue";
import request from "@/common/utils/request";
import { useRouter } from "vue-router";
import { message } from "ant-design-vue";
const router = useRouter();
const props = defineProps({
  // 消耗时长
  useTime: {
    type: Number,
    default: 0,
  },
  // 剩余的总时长
  allTime: {
    type: Number,
    default: 0,
  },
  unit: {
    type: String,
    default: "",
  },
  number_unit: {
    type: String,
    default: "",
  },
  unit_name: {
    type: String,
    default: "",
  },
  usable: {
    type: Number,
    default: 1,
  },
  current: {
    type: String,
    default: "",
  },
  consumes: {
    type: String,
    default: "",
  },
  modal: {
    type: String,
    default: ""
  }
});

const state = reactive({
  isActive: "",
  // 是否没有时长
  notAllTime: false,
});
// vo5_line_type (3(普通合成) \5(高级合成))
// 是否要充值
const topup = computed(() => {
  let useTime = props.useTime;
  if (state.isActive == "ov5_5") {
    // 高级模型, 消耗数量*2
    useTime *= 2;
  }
  let recharge = props.allTime == 0 || props.allTime < useTime;
  // 是否需要充值
  return {
    recharge,
    useTime,
  };
});

const modalTitle = computed(() => {
  return props.modal === 'ov5_3' ? '普通模型' : "高级模型";
});

const emit = defineEmits(["handleOk"]);
const dialog = ref(null);

const showModal = (data = { notAllTime: false }) => {
  // 如果没有时长, 则隐藏一些内容
  const { notAllTime } = data;
  state.notAllTime = notAllTime;
  dialog.value.showModal();
};

const closeModal = () => {
  dialog.value.closeModal();
};
const handleOk = () => {
  // if (!['ov5_3', 'ov5_5'].includes(state.isActive)) return message.error('请选择合成模型!')

  emit("handleOk");
  dialog.value.closeModal();
};

// 去充值
const goTopup = () => {
  router.push({
    name: "VoucherCenter",
  });
};

defineExpose({
  showModal,
  closeModal,
});
</script>

<template>
  <div>
    <baseModel ref="dialog" :maskClosable="false">
      <template #title>
        <div class="title_box">
          <span>{{ topup.useTime > 0 ? "确认生成" : "提示" }}</span>
        </div>
      </template>
      <template #content>
        <div class="content">
          <div class="content_text" v-if="props.usable == 1">
            <div >当前使用模型: {{ modalTitle }}</div>

            <template v-if="!state.notAllTime">
              <span>本次消耗{{ props.unit_name }}</span>
              <span style="color: red; font-weight: 900"
                >{{ props.consumes }} </span
              >{{ props.unit }}，
            </template>

            <span>剩余合成{{ props.unit_name }}</span>
            <span style="color: red; font-weight: 900">{{ props.current }}</span
            >{{ props.unit }}
          </div>

          <!-- <div class="mod_cart_list" v-if="!state.notAllTime && !topup.recharge">
            <div @click="state.isActive = 'ov5_3'" class="mod_cart_item" :class="{
                'active': state.isActive == 'ov5_3'
              }">
              <span>普通合成</span>
            </div>
            <div class="mod_cart_item" :class="{
                'active': state.isActive == 'ov5_5'
              }" @click="state.isActive = 'ov5_5'">

              <span>高级合成</span>
            </div>
          </div> -->
        </div>
      </template>
      <template #footer>
        <a-button key="back" @click="closeModal">取消</a-button>
        <a-button
          key="submit"
          type="primary"
          v-if="props.usable == 1"
          @click="handleOk"
          >确定</a-button
        >
      </template>
    </baseModel>
  </div>
</template>

<style lang="less" scoped>
.title_box {
  font-size: 16px;
  color: #1c1f23;
  font-weight: 600;
}

.content {
  .content_text {
    font-size: 14px;
    font-weight: 600 !important;
  }

  .mod_cart_list {
    display: flex;
    width: 100%;
    justify-content: space-around;
    align-items: center;
    gap: 40px;
    font-weight: 600;
    // padding: 20px;
    margin-top: 20px;

    .mod_cart_item {
      flex: 1;
      border: 1px solid #c4c4c4;
      cursor: pointer;
      padding: 10px;
      font-size: 15px;
      color: #333;
      height: 70px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      transition: all 0.3s;
      border-radius: 8px;

      &:hover {
        border-color: var(--ss-primary-color-hover);
        color: var(--ss-primary-color);
      }
    }

    .active {
      border-color: var(--ss-primary-color-hover);
      color: var(--ss-primary-color);
    }
  }
}
</style>
